package lc;

public class Q367 {
    public boolean isPerfectSquare(int num) {
        for (int i = 1; i <= num; i++) {
            int j = num / i;
            if (j == i && j % i == 0) {
                return true;
            }
            if (j < i) {
                return false;
            }
        }
        return false;
    }

    public boolean isPerfectSquare2(int num) {
        // 牛顿法
        double x0 = num;
        while (true) {
            double x1 = (x0 + num / x0) / 2;
            if (x0 - x1 < 1e-6) {
                break;
            }
            x0 = x1;
        }
        int x = (int) x0;
        return x * x == num;
    }

    public static void main(String[] args) {
        Q367 q367 = new Q367();
        System.out.println(q367.isPerfectSquare(2147483647));
    }
}
